<template>
  <div>
    <a-select
    v-model="currentValue"
    :placeholder="placeholder"
    v-bind="$attrs"
    v-on="$listeners"
  >
    <a-select-option
      v-for="(item,index) in list"
      :key="index"
      :value="item.value"
    >
      {{ item.label }}
    </a-select-option>
  </a-select>
  </div>
</template>
<script>
export default {
  name: 'SelectOfWeek',
  props: {
    // 值
    value: {
      type: [String,Number]
    },
    // 提示语
    placeholder: {
      type: String,
      default: () => '请选择'
    },
  },
  components: {},
  data() {
    return {
      // 下拉列表
      list: [],
    }
  },
  computed:{
    // 值绑定
    currentValue: {
      get: function () {
        return this.value
      },
      set: function (value) {
        this.$emit('change', value)
      }
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    getCurrentAllMonth() {
        const dataArr = [];
        const date = new Date();
        const year = date.getFullYear();
        for (let i = 1; i <= 12; i++) {
            let m = i < 10 ? "0" + i : i;
            dataArr.push({
                label: year + "年" + m + '月',
                value: year + "-" + m
            });
        }
        return dataArr;
    },
    getCurrentMonth() {
        const date = new Date();
          const year = date.getFullYear();
          let month = date.getMonth() + 1
          if (month < 10) month = `0${month}`
          return year + '-' + month
    },
    /**
     * @description: 获取下拉列表
     * @return {void}
     */
    async getData() {
      this.list = this.getCurrentAllMonth()
      this.currentValue = this.getCurrentMonth()
      setTimeout(() => {
        this.$emit('loadMonth', this.currentValue)
      }, 50);
    },
  }
}
</script>
<style lang="less" scoped>
</style>
